import { ftMenuData } from '@/api/modules/home'
import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit'

interface Istate {
  count: number
  name: string
  menuData: Idata
}
type Idata = {
  banner: any[]
  dKeyword: any[]
  keywords: any[]
  recommend: any[]
}

export const initialState: Istate = {
  count: 1,
  name: '小红',
  menuData: {
    banner: [],
    dKeyword: [],
    keywords: [],
    recommend: []
  }
}

export const fetchMenuData = createAsyncThunk('home/fetchMenuData', async () => {
  const res = await ftMenuData()
  return res
})

const reduxSlice = createSlice({
  name: 'home',
  initialState,
  reducers: {
    addCount(state, action: PayloadAction<number>) {
      state.count = state.count + action.payload
    }
  },
  extraReducers: (builder) => {
    builder.addCase(fetchMenuData.fulfilled, (state, action) => {
      console.log(action.payload)

      // state.menuData = action.payload
    })
  }
})

export const { addCount } = { ...reduxSlice.actions }

export default reduxSlice.reducer
